(function () {
    const top = document.querySelector('.topping');


    top.addEventListener('click', function (e) {
        // document.body.scrollTop = document.documentElement.scrollTop = 0;


        scrollToTop(750);

    })

    function scrollToTop(duration = 750) {
        let easeingFunction = t => t < 0.5 ? 4 * t * t * t : (t - 1) * (2 * t - 2) * (2 * t - 2) + 1;

        let originScrollY = window.pageYOffset;
        let originScrollX = window.pageXOffset; // Keep abscissa
        let originTime = Date.now();
        let passedTime = 0;
        let _scrollToTop = () => {
            if (passedTime < duration) {
                passedTime = Date.now() - originTime;
                requestAnimationFrame(_scrollToTop);
                scrollTo(originScrollX, originScrollY * (1 - easeingFunction(passedTime / duration)));
            }
        };
        _scrollToTop();
    }
})()